package com.etc.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etc.entity.MedicalHistory;
import com.etc.service.MedicalHistoryService;

@Controller
public class MedicalHistoryControler {

	@Resource
	private MedicalHistoryService medicalHistoryService;
	
	/**
	 * 查询病史
	 */
	@RequestMapping(value="selectMedicalHistory",method=RequestMethod.GET)
	public String selectByJoin(Model model,@RequestParam(value="page",required=true,defaultValue="0")int page,@RequestParam(value="pageSize",required=true,defaultValue="10")int pageSize) {
		List<MedicalHistory> medicalHistory = medicalHistoryService.selectMedicineByJoin(page, pageSize);
		int count=medicalHistoryService.countMedicineHistory();
		
		model.addAttribute("medicalHistory",medicalHistory);
		model.addAttribute("count",count);
		model.addAttribute("page",page+1);
		
		
		return "forward:/back/record-management.jsp";
	}
	
	/**
	 * 分页操作
	 * @param model
	 * @param page
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value="selectMedicalHistoryPage/{page}/{pageSize}",method=RequestMethod.GET)
	@ResponseBody
	public List<MedicalHistory> page(Model model,@PathVariable(value="page")int page,@PathVariable(value="pageSize")int pageSize) {		
		int startPage=(page-1)*pageSize;//从第几页开始显示数据
		List<MedicalHistory> medicalHistory = medicalHistoryService.selectMedicineByJoin(startPage, pageSize);
		
		int count=medicalHistoryService.countMedicineHistory();
		
		model.addAttribute("medicalHistory",medicalHistory);
		model.addAttribute("count",count);
		model.addAttribute("page",page);
		return medicalHistory;
	}
}
